﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ESOL.Business.Mst;
using ESOL.Common.Entity;

namespace ESOL.WinUI.Inv
{
    public partial class frmMaintainWareHouseQuery : BaseForm.frmBaseDialogyQueryForm
    {
        #region Variable
        private MstWarehouseEntity mSelectedWarehouse;
        public MstWarehouseEntity SelectedWarehouse
        {
            get { return mSelectedWarehouse; }
        }
        #endregion

        #region Constructor
        public frmMaintainWareHouseQuery()
        {
            InitializeComponent();
        }
        #endregion

        #region Functions
        private string GetCondition()
        {
            string condition = "";
            if (string.IsNullOrEmpty(txtWareHouseCode.Text) == false)
            {
                condition += " AND A.WAREHOUSE_CODE LIKE '%" + txtWareHouseCode.Text + "%' ";
            }
            if (string.IsNullOrEmpty(txtWareHouseName.Text) == false)
            {
                condition += " AND A.WAREHOUSE_NAME LIKE '%" + txtWareHouseName.Text + "%' ";
            }
            return condition;
        }
        private void BindDataGrid()
        {
            string condition = GetCondition();
            string orderBy = "A.SEQUENCE";
            string rowCount=Convert.ToString(1000);
            DataTable dt = MstWarehouseBs.GetByCondition(condition, orderBy, rowCount);
            gvMain.DataSource = dt;
        }
        #endregion

        #region Event
        protected override void OnShown(EventArgs e)
        {
            BindDataGrid();
            base.OnShown(e);
        }
        protected override void Click_Query()
        {
            BindDataGrid();
        }
        protected override void Click_Confirm()
        {
            if (mSelectedWarehouse == null)
            {
                MessageBox.Show("请选择一个仓库！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            this.DialogResult = DialogResult.OK;
        }
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(e.RowHandle);
            mSelectedWarehouse = new MstWarehouseEntity(dr);
        }
        #endregion

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (mSelectedWarehouse == null)
            {
                MessageBox.Show("请选择一个仓库！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            this.DialogResult = DialogResult.OK;
        }


    }
}